package me
import grails.converters.JSON
import com.mysql.cj.jdbc.MysqlConnectionPoolDataSource
import groovy.sql.Sql
import groovy.json.*
import groovy.json.JsonSlurper

class ChartparamController {

	def dataSource

    def index() { 

    	
    }

  	def store() {
  		def sql = new Sql(dataSource)
   		def results = [:]	  
    	def rows = sql.rows("select * from chart_param where chart_id=?",[params.id])
    	results.total = rows.size()
    	results = [success:true,total:rows.size(),results:rows]
    	render results as JSON
  	}


  	def delete() {
  		def sql = new Sql(dataSource)
      sql.execute("delete from chart_param where param_id = ?",params.paramId)
  		def results = [success:true]
    	render results as JSON
  	}

  	
  	def save() {
  		def sql = new Sql(dataSource)
   		def resuls = [code:0,message:'success']
   		
   		if (params.paramId==null || params.paramId=="") {
   			sql.execute("insert into chart_param(param_name,param_type,param_default,chart_id) values(?,?,?,?)",
        [params.paramName,params.paramType,params.paramDefault,params.chartId])
   	  } else {
   			sql.execute("update chart_param set param_name=?,param_type=?,param_default=?,chart_id=? where param_id=?",
        [params.paramName,params.paramType,params.paramDefault,params.chartId,params.paramId])
   		}
    	
    	//def rows = sql.execute("inser into data_source_hy_info()")

    	render resuls as JSON
  	}

}
